package com.csxy.six.controller;

import com.csxy.six.entity.Activity;
import com.csxy.six.service.ActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activity")
@Tag(name = "活动管理", description = "社团活动管理接口")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @Operation(summary = "创建活动", description = "创建一个新的社团活动")
    @PostMapping
    public boolean createActivity(@RequestBody Activity activity) {
        return activityService.save(activity);
    }

    @Operation(summary = "报名活动", description = "用户报名参加指定活动")
    @PostMapping("/{id}/join")
    public boolean joinActivity(
            @Parameter(description = "活动ID", required = true)
            @PathVariable Long id,

            @Parameter(description = "用户ID", required = true)
            @RequestParam Long userId) {
        return activityService.joinActivity(id, userId);
    }

    @Operation(summary = "活动签到", description = "用户对参加的活动进行签到")
    @PostMapping("/{id}/signin")
    public boolean signIn(
            @Parameter(description = "活动ID", required = true)
            @PathVariable Long id,

            @Parameter(description = "用户ID", required = true)
            @RequestParam Long userId) {
        return activityService.signIn(id, userId);
    }

    @Operation(summary = "获取社团活动", description = "获取指定社团的所有活动")
    @GetMapping("/club/{clubId}")
    public List<Activity> getClubActivities(
            @Parameter(description = "社团ID", required = true)
            @PathVariable Long clubId) {
        return activityService.lambdaQuery()
                .eq(Activity::getClubId, clubId)
                .list();
    }
}